#ifndef ERRORCODE_H
#define ERRORCODE_H
#include <string>
#include <memory>
#include <map>

namespace gitstore {

enum ErrorStatus {
    Success = 0,
    ParamError = 2,
    FileSystemError = 4,
    Unknown = 5,
    DatasetBaseError = 100,
    DatasetNotExist = 101,
    DatasetAlreadyExist = 102,
    DatasetListError = 103,
    DatasetCreateError = 104,
    DatasetLoadError = 105,
    DatasetSaveError = 106,
    BranchBaseError = 200,
    BranchNotExist = 201,
    BranchAlreadyExist = 202,
    BranchListError = 203,
    BranchDatasetError = 204,
    BranchLoadError = 205,
    BranchSaveError = 206,
    VersionBaseError = 300,
    VersionNotExist = 301,
    VersionAlreadyExist = 302,
    VersionLoadError = 303,
    VersionNotInBranch = 304,
    VersionCreateError = 305,
    VersionNotInDataset = 306,
    VersionSaveError = 307,
    VersionSameError = 308,
    VersionConflict = 309,
    ValueNoChange = 330,
    SubTypeOnlyCanBeStringOrBlob = 331,
    KeyNotExist = 350,
    MergeBaseError = 400,
    BlobCannotMerge = 401,
    DifferentTypeCannotMerge = 402,
    MergeConflict = 403,
    MergeFindAncestorError = 404,
    TypeCannotMerge = 405,
    DiffBaseError = 500,
    TypeCannotDiff = 501,
    DifferentTypeCannotDiff = 502,
    DBBaseError = 1000,
    DBKeyNotExist = 1001,
    DBKeyAlreadyExist = 1002,
    DBSaveError = 1003,
    DBLoadError = 1004,
    ETCDSetError = 1101,
    ETCDGetError = 1102,
    ETCDAddError = 1103,
    RevisionConflict = 1200,
};

class CErrorCodeManager {
private:
    CErrorCodeManager();

public:
    ~CErrorCodeManager();

public:
    static std::shared_ptr<CErrorCodeManager> getInstance();
    std::string getErrorMessage(ErrorStatus code);

private:
    static std::shared_ptr<CErrorCodeManager> _instance;
    std::map<ErrorStatus, std::string> _map_err_msg;

private:
    void loadErrorMessage();
};

//struct ErrorCode {
//    ErrorCode();
//    ErrorCode(ErrorStatus s);
//    std::string toJsonString();
//    operator std::string() const;

//    ErrorStatus status;
//    const std::string msg;

//};
}

#endif // ERRORCODE_H
